package by.dkusch.aircompany.webapp.page.base.common;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.event.Broadcast;
import org.apache.wicket.markup.html.panel.Panel;

import by.dkusch.aircompany.webapp.page.base.enums.DirectionType;
import by.dkusch.aircompany.webapp.page.base.enums.SelectorType;
import by.dkusch.aircompany.webapp.page.base.events.SelectorDirectionEvent;

public class SelectorActionPanel<ID> extends Panel {

	private static final long serialVersionUID = 1L;

	public SelectorActionPanel(String id, final ID entityID, final SelectorType selector) {
		super(id);

		add(new AjaxLink<Void>("selectFrom") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				SelectorDirectionEvent<ID> selectorEvent = new SelectorDirectionEvent<ID>();
				selectorEvent.setTarget(target);
				selectorEvent.setEntityID(entityID);
				selectorEvent.setDirection(DirectionType.DIRECTION_FROM);
				selectorEvent.setSelector(selector);
				send(getPage(), Broadcast.BREADTH, selectorEvent);
			}

		});

		add(new AjaxLink<Void>("selectTo") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				SelectorDirectionEvent<ID> selectorEvent = new SelectorDirectionEvent<ID>();
				selectorEvent.setTarget(target);
				selectorEvent.setEntityID(entityID);
				selectorEvent.setDirection(DirectionType.DIRECTION_TO);
				selectorEvent.setSelector(selector);
				send(getPage(), Broadcast.BREADTH, selectorEvent);
			}

		}.setVisible(SelectorType.AIRPORT.equals(selector)));

	};
}
